<!-- 我的收藏页面 -->
<template>
    <div class="collection-container">
      <!-- 用户收藏的招聘岗位 -->
      <div class="company-list" v-if="isUser">
        <ul>
          <li 
            v-for="(item,index) in userCollectionList" 
            :key="index" 
            class="li-bg"
            @click="toRecruitDetailHandle(item.companyAid,item.recruitmentInfoAid)"
          >
            <img 
              :src="item.companyBgImage ? item.companyBgImage : 'https://recruitment-files.oss-cn-chengdu.aliyuncs.com/company1647700939000.jpg'" 
              alt=""
              class="bg-style"
            >
            <div class="mask">
              <h3>{{item.companyName}}</h3>
              <h3>收藏的岗位： {{item.positionName}}</h3>
            </div>
          </li>
        </ul>          
      </div>

      <!-- 企业收藏的用户 -->
      <div class="company-list" v-if="!isUser">
        <ul>
          <li 
            v-for="(item,index) in companyCollectionList" 
            :key="index" 
            class="li-bg"
            @click="toUserJobList(item.userJobAid)"
          >
            <img 
              :src="item.userAvatar ? item.userAvatar : 'https://recruitment-files.oss-cn-chengdu.aliyuncs.com/user/hr1.jpg'" 
              alt=""
              class="bg-style"
            >
            <div class="mask">
              <h3>收藏的用户： {{item.userName}}</h3>
              <h3 class="user-expect-work">该用户的意向工作:</h3>
              <h3 class="user-expect-work">{{item.userExpectWork}}</h3>
            </div>
          </li>
        </ul>          
      </div>

      <el-empty v-if="isLogin" description="请先登录或注册" class="empty_style"></el-empty>

      <el-empty v-if="userCollectionList.length === 0 && isUser" description="您没有收藏的岗位！先去收藏吧！" class="empty_style"></el-empty>
      <el-empty v-if="companyCollectionList.length === 0 && !isUser" description="您没有收藏的用户及用户的意向工作！" class="empty_style"></el-empty>
    </div>
</template>

<script>
import { getCurrentCollection } from '../../../api/collection/index';
import { getStore } from '../../../storage/storage';
export default {
  data () {
    return {
      userCollectionList:[], //当前登陆用户收藏的招聘信息
      companyCollectionList: [], // 当前登陆企业收藏的用户列表
      isUser: true,
      isLogin: false,
    }
  },
  created(){
    // console.log(getStore("account"));
    // 得到当前登陆的收藏列表
    this.getCurrentCollectionFunc();

    // 判断当前是否登陆
    this.checkHaveAccountFunc();
  },
  methods:{
    // 得到当前登陆的收藏列表
    getCurrentCollectionFunc(){
      const params = {
        account: getStore("account"),
      }
      getCurrentCollection(params).then(res=>{
        this.isUser = res.data.data.isUser;
        this.userCollectionList = res.data.data.userCollectionList;
        this.companyCollectionList = res.data.data.companyCollectionList;
        if(res.data.data.companyCollectionList.length === 0 
            && res.data.data.userCollectionList.length === 0
            && res.data.data.isUser === false
          ){
          this.$message({
            message: "没有收藏的！",
            type: 'info',
            duration: 800,
          })
        }
        if(res.data.data.userCollectionList.length === 0 
            && res.data.data.companyCollectionList === 0
            && res.data.data.isUser === true
          ){
          this.$message({
            message: "您还没有收藏的岗位，快去收藏吧！",
            type: 'info',
            duration: 800,
          })
        }
      })
    },

    // 点击职位去招聘职位信息界面
    toRecruitDetailHandle(companyAid,recruitmentInfoAid){
      this.$router.push({
        path: "/reception/recruitInfoDetail",
        query: {
          companyAid: companyAid,
          recruitmentInfoAid: recruitmentInfoAid
        }
      });
    },

     // 去该用户的求职列表页面
    toUserJobList(userJobAid){
      this.$router.push({
        path: '/reception/userPage',
        query: {
          userJobAid,
        }
      });
    },

    // 判断当前是否登陆
    checkHaveAccountFunc(){
      if(getStore("account") !== null){
        this.isLogin = false;
      }else{
        this.isLogin = true;
      }
    }

  }
}
</script>

<style scoped>
@import '../../../assets/css/reception/myCollection.css';
</style>
